package com.dmx.cep.action.contentManage;

import com.dmx.cep.entity.FtpServerConfig;
import com.dmx.cep.service.ContentService;
import com.dmx.fw.exception.GeneralException;
import com.dmx.fw.exception.GeneralExceptionHandler;
import com.dmx.fw.web.struts2.action.BaseAction;

public class FtpManageAction extends BaseAction{
	
	private ContentService contentService;
	
	private FtpServerConfig ftpConfig;
	
	private Long id;
	
	//进入增加输入界面
	public String doAddInput(){
		
		
		return INPUT;
	}
	
	//执行增加提交
	public String doAddSubmit() throws Exception{
		try {
			contentService.saveObject(ftpConfig);

			this.setSuccessinfo(this.getText("info.addSuccess"));
			// this.setAjaxJsonUrlResult(resultUrl);
			return "list";
		} catch (Exception e) {
			GeneralException ge = GeneralExceptionHandler.Handle(e);
			this.setErrorInfo(this.getText(ge.getMessage()));
			return doAddInput();
		}
	}
	
	//进入修改输入界面
	public String doEditInput(){
		if(ftpConfig==null)
			ftpConfig=(FtpServerConfig)contentService.getObject(FtpServerConfig.class, id);
		
		return INPUT;
	}
	
	//执行修改提交
	public String doEditSubmit() throws Exception{
		try {
			contentService.saveObject(ftpConfig);

			this.setSuccessinfo(this.getText("info.modifySuccess"));
			// this.setAjaxJsonUrlResult(resultUrl);
			return "list";
		} catch (Exception e) {
			GeneralException ge = GeneralExceptionHandler.Handle(e);
			this.setErrorInfo(this.getText(ge.getMessage()));
			return doEditInput();
		}
	}
	
	public String doDelete() throws Exception{
		contentService.removeObject(FtpServerConfig.class, id);
		
		this.setSuccessinfo(this.getText("info.deleteSuccess"));
		//this.setAjaxJsonUrlResult(resultUrl);
		return "list";
	}

	public ContentService getContentService() {
		return contentService;
	}

	public void setContentService(ContentService contentService) {
		this.contentService = contentService;
	}

	public FtpServerConfig getFtpConfig() {
		return ftpConfig;
	}

	public void setFtpConfig(FtpServerConfig ftpConfig) {
		this.ftpConfig = ftpConfig;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
}
